/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

/**
 *
 * @author James
 */
@Entity
public class Outlet implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long   id;
    private String name;
    private String address1;
    private String address2;
    private String postalCode;
    private String countryCode;
    private String phone;
    private String country;
    private String province;
    private String city;
    private String timezone;
    private String businessEmail;
    private int    reservationNoShowFee; // dollar * 100 + cents ($2.5 = 250)
    private int    reservationCancelFee; // postive: dollar * 100 + cents ($2.5 = 250), negative: percentage of the items paid
    private int    reservableMinimumLength; // postive: number of minutes, 0: reservation not allowed
    private int    reservableMaximumLength; // postive: number of minutes, 0: reservation not allowed
    private int    reservationMinimumLeadTime; // postive: number of minutes
    private int    reservationMaximumLeadTime; // postive: number of minutes
    private boolean active;
    private boolean deleted;
    @OneToOne(cascade={CascadeType.ALL})
    private Files  layout;
    @ManyToOne
    private Partner thePartner;
    @OneToMany(cascade={CascadeType.PERSIST}, mappedBy="theOutlet")
    private List<ReservableUnit> listOfReservableUnits; // what can be reserved
    @OneToMany(cascade={CascadeType.ALL}, mappedBy="theOutlet")
    private List<ItemCategory> sellingItemCategories; // This contains some items only available at this particular outlet
    @OneToMany(cascade={CascadeType.PERSIST})
    private List<CustomerTransactions> listOfTransactions; 
    @OneToMany(cascade={CascadeType.ALL})
    private List<Files> listOfPictures;
    
    public Outlet() { 
        this.active                 = true;
        this.deleted                = false;
        this.layout                 = null;
        this.listOfReservableUnits  = new ArrayList<ReservableUnit>();
        this.sellingItemCategories  = new ArrayList<ItemCategory>();
        this.listOfTransactions     = new ArrayList<CustomerTransactions>();
        this.listOfPictures         = new ArrayList<Files>();
    }
    
    public void createOutlet(String name, String address1, String address2, String postalCode, String countryCode, String phone, String country, String province, String city, String businessEmail, Files layout, Partner thePartner) {
        this.name                 = name;
        this.address1             = address1;
        this.address2             = address2;
        this.postalCode           = postalCode;
        this.countryCode          = countryCode;
        this.phone                = phone;
        this.country              = country;
        this.province             = province;
        this.city                 = city;
        this.businessEmail        = businessEmail;
        this.layout               = layout;
        this.thePartner           = thePartner;
        this.timezone             = thePartner.getTimezone();
        this.reservationNoShowFee = thePartner.getReservationNoShowFee();
        this.reservationCancelFee = thePartner.getReservationCancelFee();
        this.reservableMinimumLength    = thePartner.getReservableMinimumLength();
        this.reservableMaximumLength    = thePartner.getReservableMaximumLength();
        this.reservationMinimumLeadTime = thePartner.getReservationMinimumLeadTime();
        this.reservationMaximumLeadTime = thePartner.getReservationMaximumLeadTime();
    } 
    
    public void addItemCategory(ItemCategory theItemCategory) {
        this.sellingItemCategories.add(theItemCategory);
    }
    
    public void addPicture(Files thePicture) {
        this.listOfPictures.add(thePicture);
    } 
    
    public void addReservableUnit(ReservableUnit theUnit) {
        this.listOfReservableUnits.add(theUnit);
    }
    
    //Getters and Setters
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTimezone() {
        return timezone;
    }

    public void setTimezone(String timezone) {
        this.timezone = timezone;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public String getAddress1() { 
        return address1;
    }

    public void setAddress1(String address1) {
        this.address1 = address1;
    }

    public String getAddress2() {
        return address2;
    }

    public void setAddress2(String address2) {
        this.address2 = address2;
    }

    public String getBusinessEmail() {
        return businessEmail;
    }

    public void setBusinessEmail(String businessEmail) {
        this.businessEmail = businessEmail;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public Partner getPartner() {
        return thePartner;
    }

    public void setPartner(Partner thePartner) {
        this.thePartner = thePartner;
    }

    public List<CustomerTransactions> getListOfTransactions() {
        return listOfTransactions;
    }

    public void setListOfTransactions(List<CustomerTransactions> listOfTransactions) {
        this.listOfTransactions = listOfTransactions;
    }

    public List<ItemCategory> getItemCategories() {
        return sellingItemCategories;
    }

    public void setItemCategories(List<ItemCategory> sellingItemCategories) {
        this.sellingItemCategories = sellingItemCategories;
    }

    public String getCountryCode() {
        return countryCode;
    }

    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPostalCode() {
        return postalCode;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    public Files getLayout() {
        return layout;
    }

    public void setLayout(Files layout) {
        this.layout = layout;
    }

    public int getReservationMinimumLeadTime() {
        return reservationMinimumLeadTime;
    }

    public void setReservationMinimumLeadTime(int reservationMinimumLeadTime) {
        this.reservationMinimumLeadTime = reservationMinimumLeadTime;
    }

    public int getReservableMinimumLength() {
        return reservableMinimumLength;
    }

    public void setReservableMinimumLength(int reservableMinimumLength) {
        this.reservableMinimumLength = reservableMinimumLength;
    }

    public int getReservableMaximumLength() {
        return reservableMaximumLength;
    }

    public void setReservableMaximumLength(int reservableMaximumLength) {
        this.reservableMaximumLength = reservableMaximumLength;
    }

    public int getReservationMaximumLeadTime() {
        return reservationMaximumLeadTime;
    }

    public void setReservationMaximumLeadTime(int reservationMaximumLeadTime) {
        this.reservationMaximumLeadTime = reservationMaximumLeadTime;
    }

    public int getReservationNoShowFee() {
        return reservationNoShowFee;
    }

    public void setReservationNoShowFee(int reservationNoShowFee) {
        this.reservationNoShowFee = reservationNoShowFee;
    }

    public int getReservationCancelFee() {
        return reservationCancelFee;
    }

    public void setReservationCancelFee(int reservationCancelFee) {
        this.reservationCancelFee = reservationCancelFee;
    }

    public List<ReservableUnit> getListOfReservationUnits() {
        return listOfReservableUnits;
    }

    public void setListOfReservationUnits(List<ReservableUnit> listOfReservableUnits) {
        this.listOfReservableUnits = listOfReservableUnits;
    }

    public List<Files> getListOfPictures() {
        return listOfPictures;
    }

    public void setListOfPictures(List<Files> listOfPictures) {
        this.listOfPictures = listOfPictures;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Outlet)) {
            return false;
        }
        Outlet other = (Outlet) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Outlet[ id=" + id + " ]";
    }
    
}
